﻿using System;
using System.Runtime.InteropServices;
using System.Text;

namespace VMExplorer.Win32
{
  partial class Native
  {
    [DllImport("psapi.dll", SetLastError = true)]
    public static extern UInt32 GetMappedFileName(SafeProcessHandle hProcess, IntPtr lpv, StringBuilder lpFilename, UInt32 nSize);

    [DllImport("kernel32.dll", SetLastError = true)]
    public static extern UInt32 QueryDosDevice(string lpDeviceName, StringBuilder lpTargetPath, UInt32 ucchMax);

    [DllImport("kernel32.dll", SetLastError = true)]
    public static extern bool CloseHandle(IntPtr hObject);

    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr GetModuleHandle(string lpModuleName);

    [DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
    public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);

    [StructLayout(LayoutKind.Sequential, Size = 0x04)]
    public struct HANDLE
    {
      public IntPtr Handle;
    }

    [StructLayout(LayoutKind.Sequential, Size = 0x08)]
    public struct LIST_ENTRY
    {
      public IntPtr Flink; // LIST_ENTRY*
      public IntPtr Blink; // LIST_ENTRY*
    };

    [StructLayout(LayoutKind.Sequential, Size = 0x08)]
    public struct UNICODE_STRING
    {
      public UInt16 Length;
      public UInt16 MaximumLength;
      public IntPtr Buffer;
    };

    [StructLayout(LayoutKind.Sequential, Size = 0x10)]
    public struct RTL_DRIVE_LETTER_CURDIR
    {
      public UInt16 Flags;
      public UInt16 Length;
      public UInt32 TimeStamp;
      public UNICODE_STRING DosPath;
    };

    //[StructLayout (LayoutKind.Explicit, Size = 0x08)]
    //public struct EXCEPTION_REGISTRATION_RECORD
    //{
    //  [FieldOffset (0x00)]
    //  public IntPtr pNext; // (PEXCEPTION_REGISTRATION_RECORD)
    //  [MarshalAs (UnmanagedType.FunctionPtr)]
    //  [FieldOffset (0x04)]
    //  public IntPtr pfnHandler; // (FARPROC)
    //};

    //public class EXCEPTION_REGISTRATION_RECORDWrapper
    //{
    //  EXCEPTION_REGISTRATION_RECORD _err;
    //  public EXCEPTION_REGISTRATION_RECORDWrapper (EXCEPTION_REGISTRATION_RECORD err)
    //  {
    //    _err = err;
    //  }

    //  public IntPtr NextAddress { get { return _err.pNext; } }
    //  public EXCEPTION_REGISTRATION_RECORDWrapper Next { get { return new EXCEPTION_REGISTRATION_RECORDWrapper ((EXCEPTION_REGISTRATION_RECORD)Marshal.PtrToStructure (_err.pNext, typeof (EXCEPTION_REGISTRATION_RECORD))); } }

    //  public IntPtr Handler { get { return _err.pfnHandler; } }

    //}


    [StructLayout(LayoutKind.Sequential, Size = 0x10)]
    public struct ACTIVATIONCONTEXT
    {
      public UInt32 Signature;
      public UInt32 u1;
      public UInt32 u2;
      public UInt32 Size;
      public UInt32 u3;
      public UInt32 u4;
      public UInt32 u5;
      public UInt32 u6;
      public UInt32 u7;
      public UInt32 u8;
      public UInt32 u9;
      public UInt32 u10;
      public UInt32 SshDOffset;
    };

  }


}